<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="root">

    </div>
</body>
<script src="../react.js"></script>
<script src="../react-dom.js"></script>
<script src="https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js"></script>
<script type="text/babel">

class App extends React.Component{
        state={
            num:0
        }
        constructor(){
            // this指向当前组件实例对象
            super();
            this.add = this.add.bind(this)
        }
        render(){
            // this指向当前组件实例对象
            console.log(this)
            return(
                <div>
                    <h1>{this.state.num}</h1>
                    <button onClick={()=>{
                        // this指向当前组件实例对象
                        this.state.num++;
                        this.setState({
                            num:this.state.num
                        })
                    }}>++</button>
                    {
                        //  <button onClick={this.add.bind(this)}>+5</button>
                    }
                    <button onClick={this.add}>+5</button>

                    <button onClick={()=>this.addBig()}>+10</button>
                    <button onClick={this.reduce}>-5 </button>
                </div>
            )
        }
        add(){
            console.log(this)
            this.state.num+=5;
            this.setState({
                num:this.state.num
            })
            this.addBig();
        }
        addnum(){
             // this指向当前组件实例对象
            console.log(this)
        }
        addBig(){
            console.log(this)
            this.state.num+=10;
            this.setState({
                num:this.state.num
            })
        }
        reduce=()=>{
            this.state.num-=5;
            this.setState({
                num:this.state.num
            })
        }
    }

    ReactDOM.render(<App/>,document.getElementById("root"))
</script>
</html>